package o;

import android.os.AsyncTask;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.downloadengine.api.SessionDownloadTask;
import com.huawei.appgallery.foundation.card.base.bean.AppInfoBean;
import com.huawei.appgallery.foundation.card.base.bean.BaseDistCardBean;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CountDownLatch;
import o.dqw.c;

public class dwf {

    public interface a {
        void ˊ(@Nullable List<SessionDownloadTask> list);
    }

    static class b extends AsyncTask<Map<String, AppInfoBean>, Void, List<SessionDownloadTask>> {
        private a ˋ;

        @Nullable
        protected /* synthetic */ Object doInBackground(Object[] objArr) {
            return ॱ((Map[]) objArr);
        }

        protected /* synthetic */ void onPostExecute(Object obj) {
            ˊ((List) obj);
        }

        public b(a aVar) {
            this.ˋ = aVar;
        }

        @Nullable
        protected List<SessionDownloadTask> ॱ(Map<String, AppInfoBean>... mapArr) {
            if (mapArr == null || mapArr.length <= 0) {
                return null;
            }
            return dwf.ˎ(mapArr[0]);
        }

        protected void ˊ(List<SessionDownloadTask> list) {
            super.onPostExecute(list);
            if (this.ˋ != null) {
                this.ˋ.ˊ(list);
            }
        }
    }

    static class e implements c {
        private List<SessionDownloadTask> ˏ;
        private CountDownLatch ॱ;

        public e(CountDownLatch countDownLatch, @NonNull List<SessionDownloadTask> list) {
            this.ॱ = countDownLatch;
            this.ˏ = list;
        }

        public void ˋ(SessionDownloadTask sessionDownloadTask) {
            this.ˏ.add(sessionDownloadTask);
            this.ॱ.countDown();
            Logger.ˎ("DependBundleAppDownloadManager", "latch size down");
        }

        public void ॱ() {
            Logger.ˋ("DependBundleAppDownloadManager", "get app bundle info fail. ");
            this.ॱ.countDown();
            Logger.ˎ("DependBundleAppDownloadManager", "latch size down");
        }
    }

    public static void ˏ(Map<String, AppInfoBean> map, a aVar) {
        Logger.ˎ("DependBundleAppDownloadManager", "getDependDownloadTaskListAsync");
        new b(aVar).execute(new Map[]{map});
    }

    private static List<SessionDownloadTask> ˎ(Map<String, AppInfoBean> map) {
        List<SessionDownloadTask> arrayList = new ArrayList();
        if (CollectCheck.isEmpty((Map) map)) {
            Logger.ˋ("DependBundleAppDownloadManager", "dpbeanList is empty.");
        } else {
            Logger.ˎ("DependBundleAppDownloadManager", "latch size=" + map.size());
            CountDownLatch countDownLatch = new CountDownLatch(map.size());
            for (AppInfoBean appInfoBean : map.values()) {
                BaseDistCardBean baseDistCardBean = new BaseDistCardBean();
                baseDistCardBean.ͺ(appInfoBean.ˈ());
                baseDistCardBean.ˏˎ(appInfoBean.ˏॱ());
                if (Logger.ˎ()) {
                    Logger.ˏ("DependBundleAppDownloadManager", appInfoBean.toString());
                }
                if (appInfoBean.ˈ() == 1) {
                    Logger.ˎ("DependBundleAppDownloadManager", "is bundle app.");
                    new dqw().ˏ(baseDistCardBean, new e(countDownLatch, arrayList));
                } else {
                    SessionDownloadTask sessionDownloadTask = new SessionDownloadTask();
                    sessionDownloadTask.ʼ(appInfoBean.ˏॱ());
                    sessionDownloadTask.ʽ(appInfoBean.ˋॱ());
                    sessionDownloadTask.ॱॱ(appInfoBean.ʽ());
                    arrayList.add(sessionDownloadTask);
                    Logger.ˎ("DependBundleAppDownloadManager", "latch size down");
                    countDownLatch.countDown();
                }
            }
            try {
                countDownLatch.await();
            } catch (InterruptedException e) {
                Logger.ˋ("DependBundleAppDownloadManager", "InterruptedException");
            } finally {
                arrayList = "DependBundleAppDownloadManager";
                Logger.ˎ(arrayList, "getDependDownloadTaskList end.");
            }
        }
        return arrayList;
    }
}
